package com.atguigu.guli.service.cms.controller.admin;


import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.cms.entity.Ad;
import com.atguigu.guli.service.cms.service.AdService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 广告推荐 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2021-07-07
 */
@Api(tags = "管理广告")
@RestController
@CrossOrigin
@RequestMapping("/admin/cms/ad")
public class AdminAdController {

    @Autowired
    private AdService adService;

    //查询所有的广告
    @ApiOperation(value = "查询所有的广告")
    @GetMapping("getAdAll")
    public R getAdAll() {
        Map ads = adService.getAdAll();
        return R.ok().data(ads);
    }

    // 添加广告
    @ApiOperation(value = "添加广告")
    @PostMapping("saveAd")
    public R saveAd(@RequestBody Ad ad) {
        adService.save(ad);
        return R.ok();
    }

    // 删除广告
    @ApiOperation(value = "删除广告")
    @DeleteMapping("deleteAd/{AdId}")
    public R deleteAd(@PathVariable("AdId") String AdId) {
        adService.removeById(AdId);
        return R.ok();
    }

    // 修改广告
    @ApiOperation(value = "修改广告")
    @PutMapping("updateAd")
    public R updateAd(@RequestBody Ad ad) {
        adService.updateById(ad);
        return R.ok();
    }

}

